<h1>Listing batches</h1>

<p><b><%= link_to "New request...", :action => 'new' %></b></p>

<table width="100%">
  <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Description</th>
    <th>Status</th>
  </tr>

<% for batch in @batches do 
     passed = 0
     failed = 0
     pending = 0
     running = 0
     error = 0
     builds = batch.build_runs
     builds.each do |build|
       if build.status =~ /passed/ then
         passed += 1
       elsif build.status =~ /pending/ then
         pending += 1
       elsif build.status =~ /running/ then
         running += 1
       elsif build.status =~ /failed/ then
         failed += 1
       else
         error += 1
       end
     end
     status = ""
     status = "<span class='batch_passed'>" +passed.to_s + " passed</span>"
     if failed > 0
       status += ", <span class='batch_failed'>" + failed.to_s + " failed</span>"
     end
     if running > 0
       status += ", <span class='batch_running'>" + running.to_s + " running</span>"
     end
     if pending > 0
       status += ", <span class='batch_pending'>" + pending.to_s + " pending</span>"
     end
     if error > 0
       status += ", <span class='batch_error'>" + error.to_s + " error</span>"
     end
%>
  <tr>
    <td align="center"><%= link_to batch.id, :action => 'show', :id => batch.id %></td>
    <td align="center"><span class='batch_name' style='background-color:<%= batch.colour %>;'><%= link_to batch.name, :action => 'show', :id => batch.id %></span></td>
    <td align="center"><%= batch.description %></td>
    <td align="center"><%= status %></td>
  </tr>
<% end %>
</table>